import 'package:safetymonitor/generated/json/base/json_convert_content.dart';
import 'package:safetymonitor/app/data/entities/application/device_histroy_data_entity.dart';

DeviceHistroyDataEntity $DeviceHistroyDataEntityFromJson(Map<String, dynamic> json) {
  final DeviceHistroyDataEntity deviceHistroyDataEntity = DeviceHistroyDataEntity();
  final dynamic companyId = json['companyId'];
  if (companyId != null) {
    deviceHistroyDataEntity.companyId = companyId;
  }
  final dynamic systemId = json['systemId'];
  if (systemId != null) {
    deviceHistroyDataEntity.systemId = systemId;
  }
  final dynamic systemCode = json['systemCode'];
  if (systemCode != null) {
    deviceHistroyDataEntity.systemCode = systemCode;
  }
  final dynamic deviceCode = json['deviceCode'];
  if (deviceCode != null) {
    deviceHistroyDataEntity.deviceCode = deviceCode;
  }
  final List<String>? threshold = (json['threshold'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<String>(e) as String).toList();
  if (threshold != null) {
    deviceHistroyDataEntity.threshold = threshold;
  }
  final List<DeviceHistroyDataPoints>? points = (json['points'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<DeviceHistroyDataPoints>(e) as DeviceHistroyDataPoints).toList();
  if (points != null) {
    deviceHistroyDataEntity.points = points;
  }
  final int? notificationCategory = jsonConvert.convert<int>(json['notificationCategory']);
  if (notificationCategory != null) {
    deviceHistroyDataEntity.notificationCategory = notificationCategory;
  }
  final List<DeviceHistroyDataThresholdVals>? thresholdVals = (json['thresholdVals'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<DeviceHistroyDataThresholdVals>(e) as DeviceHistroyDataThresholdVals).toList();
  if (thresholdVals != null) {
    deviceHistroyDataEntity.thresholdVals = thresholdVals;
  }
  final dynamic queryStartTime = json['queryStartTime'];
  if (queryStartTime != null) {
    deviceHistroyDataEntity.queryStartTime = queryStartTime;
  }
  final dynamic queryEndTime = json['queryEndTime'];
  if (queryEndTime != null) {
    deviceHistroyDataEntity.queryEndTime = queryEndTime;
  }
  return deviceHistroyDataEntity;
}

Map<String, dynamic> $DeviceHistroyDataEntityToJson(DeviceHistroyDataEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['companyId'] = entity.companyId;
  data['systemId'] = entity.systemId;
  data['systemCode'] = entity.systemCode;
  data['deviceCode'] = entity.deviceCode;
  data['threshold'] = entity.threshold;
  data['points'] = entity.points.map((v) => v.toJson()).toList();
  data['notificationCategory'] = entity.notificationCategory;
  data['thresholdVals'] = entity.thresholdVals.map((v) => v.toJson()).toList();
  data['queryStartTime'] = entity.queryStartTime;
  data['queryEndTime'] = entity.queryEndTime;
  return data;
}

extension DeviceHistroyDataEntityExtension on DeviceHistroyDataEntity {
  DeviceHistroyDataEntity copyWith({
    dynamic companyId,
    dynamic systemId,
    dynamic systemCode,
    dynamic deviceCode,
    List<String>? threshold,
    List<DeviceHistroyDataPoints>? points,
    int? notificationCategory,
    List<DeviceHistroyDataThresholdVals>? thresholdVals,
    dynamic queryStartTime,
    dynamic queryEndTime,
  }) {
    return DeviceHistroyDataEntity()
      ..companyId = companyId ?? this.companyId
      ..systemId = systemId ?? this.systemId
      ..systemCode = systemCode ?? this.systemCode
      ..deviceCode = deviceCode ?? this.deviceCode
      ..threshold = threshold ?? this.threshold
      ..points = points ?? this.points
      ..notificationCategory = notificationCategory ?? this.notificationCategory
      ..thresholdVals = thresholdVals ?? this.thresholdVals
      ..queryStartTime = queryStartTime ?? this.queryStartTime
      ..queryEndTime = queryEndTime ?? this.queryEndTime;
  }
}

DeviceHistroyDataPoints $DeviceHistroyDataPointsFromJson(Map<String, dynamic> json) {
  final DeviceHistroyDataPoints deviceHistroyDataPoints = DeviceHistroyDataPoints();
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    deviceHistroyDataPoints.name = name;
  }
  final int? status = jsonConvert.convert<int>(json['status']);
  if (status != null) {
    deviceHistroyDataPoints.status = status;
  }
  final dynamic unit = json['unit'];
  if (unit != null) {
    deviceHistroyDataPoints.unit = unit;
  }
  final List<DeviceHistroyDataPointsData>? data = (json['data'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<DeviceHistroyDataPointsData>(e) as DeviceHistroyDataPointsData).toList();
  if (data != null) {
    deviceHistroyDataPoints.data = data;
  }
  return deviceHistroyDataPoints;
}

Map<String, dynamic> $DeviceHistroyDataPointsToJson(DeviceHistroyDataPoints entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['name'] = entity.name;
  data['status'] = entity.status;
  data['unit'] = entity.unit;
  data['data'] = entity.data.map((v) => v.toJson()).toList();
  return data;
}

extension DeviceHistroyDataPointsExtension on DeviceHistroyDataPoints {
  DeviceHistroyDataPoints copyWith({
    String? name,
    int? status,
    dynamic unit,
    List<DeviceHistroyDataPointsData>? data,
  }) {
    return DeviceHistroyDataPoints()
      ..name = name ?? this.name
      ..status = status ?? this.status
      ..unit = unit ?? this.unit
      ..data = data ?? this.data;
  }
}

DeviceHistroyDataPointsData $DeviceHistroyDataPointsDataFromJson(Map<String, dynamic> json) {
  final DeviceHistroyDataPointsData deviceHistroyDataPointsData = DeviceHistroyDataPointsData();
  final String? time = jsonConvert.convert<String>(json['time']);
  if (time != null) {
    deviceHistroyDataPointsData.time = time;
  }
  final String? value = jsonConvert.convert<String>(json['value']);
  if (value != null) {
    deviceHistroyDataPointsData.value = value;
  }
  return deviceHistroyDataPointsData;
}

Map<String, dynamic> $DeviceHistroyDataPointsDataToJson(DeviceHistroyDataPointsData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['time'] = entity.time;
  data['value'] = entity.value;
  return data;
}

extension DeviceHistroyDataPointsDataExtension on DeviceHistroyDataPointsData {
  DeviceHistroyDataPointsData copyWith({
    String? time,
    String? value,
  }) {
    return DeviceHistroyDataPointsData()
      ..time = time ?? this.time
      ..value = value ?? this.value;
  }
}

DeviceHistroyDataThresholdVals $DeviceHistroyDataThresholdValsFromJson(Map<String, dynamic> json) {
  final DeviceHistroyDataThresholdVals deviceHistroyDataThresholdVals = DeviceHistroyDataThresholdVals();
  final int? alarmType = jsonConvert.convert<int>(json['alarmType']);
  if (alarmType != null) {
    deviceHistroyDataThresholdVals.alarmType = alarmType;
  }
  final double? thresholdVal = jsonConvert.convert<double>(json['thresholdVal']);
  if (thresholdVal != null) {
    deviceHistroyDataThresholdVals.thresholdVal = thresholdVal;
  }
  final dynamic color = json['color'];
  if (color != null) {
    deviceHistroyDataThresholdVals.color = color;
  }
  final int? notificationCategory = jsonConvert.convert<int>(json['notificationCategory']);
  if (notificationCategory != null) {
    deviceHistroyDataThresholdVals.notificationCategory = notificationCategory;
  }
  final int? alarmLevel = jsonConvert.convert<int>(json['alarmLevel']);
  if (alarmLevel != null) {
    deviceHistroyDataThresholdVals.alarmLevel = alarmLevel;
  }
  return deviceHistroyDataThresholdVals;
}

Map<String, dynamic> $DeviceHistroyDataThresholdValsToJson(DeviceHistroyDataThresholdVals entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['alarmType'] = entity.alarmType;
  data['thresholdVal'] = entity.thresholdVal;
  data['color'] = entity.color;
  data['notificationCategory'] = entity.notificationCategory;
  data['alarmLevel'] = entity.alarmLevel;
  return data;
}

extension DeviceHistroyDataThresholdValsExtension on DeviceHistroyDataThresholdVals {
  DeviceHistroyDataThresholdVals copyWith({
    int? alarmType,
    double? thresholdVal,
    dynamic color,
    int? notificationCategory,
    int? alarmLevel,
  }) {
    return DeviceHistroyDataThresholdVals()
      ..alarmType = alarmType ?? this.alarmType
      ..thresholdVal = thresholdVal ?? this.thresholdVal
      ..color = color ?? this.color
      ..notificationCategory = notificationCategory ?? this.notificationCategory
      ..alarmLevel = alarmLevel ?? this.alarmLevel;
  }
}